import 'package:flutter/material.dart';
import 'package:zchope_student/utils/utils.dart';

import '../const.dart';

class EditText extends StatelessWidget {
  final data;
  final name;
  final labelText;
  final value;
  final icon;
  final keyboardType;

  const EditText(
      {Key key,
      this.data,
      this.name,
      this.labelText,
      this.value,
      this.icon,
      this.keyboardType})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return TextField(
      keyboardType: keyboardType,
      controller: TextEditingController.fromValue(TextEditingValue(
          text: value,
          selection: TextSelection.fromPosition(TextPosition(
              affinity: TextAffinity.downstream, offset: value.length)))),
      onChanged: (value) {
        data[name] = value;
      },
      style: TextStyle(fontSize: 18, color: Const.gold),
      decoration: InputDecoration(
        labelText: labelText,
        labelStyle: TextStyle(color: Const.gold, fontSize: 18),
        focusedBorder: UnderlineInputBorder(
            borderSide: BorderSide(
          color: Const.gold,
          width: 1,
        )),
        enabledBorder: UnderlineInputBorder(
            borderSide: BorderSide(
          color: Const.gold,
          width: 1,
        )),
      ),
    );
  }
}

class PassField extends StatefulWidget {
  final Key fieldKey;
  final String labelText;
  final String helperText;
  final Map map;
  final String mapKey;

  const PassField(
      {Key key,
      this.fieldKey,
      this.labelText,
      this.helperText,
      this.map,
      this.mapKey})
      : super(key: key);

  @override
  _PassFieldState createState() => _PassFieldState();
}

class _PassFieldState extends State<PassField> {
  bool _obscureText = true;

  @override
  Widget build(BuildContext context) {
    return TextField(
      onChanged: (value) {
        widget.map[widget.mapKey] = value;
      },
      key: widget.fieldKey,
      obscureText: _obscureText,
      style: TextStyle(fontSize: 16, color: Const.gold),
      decoration: InputDecoration(
        labelText: widget.labelText,
        labelStyle: TextStyle(color: Const.gold, fontSize: 18),
        focusedBorder: UnderlineInputBorder(
            borderSide: BorderSide(
          color: Const.gold,
          width: 1,
        )),
        enabledBorder: UnderlineInputBorder(
            borderSide: BorderSide(
          color: Const.gold,
          width: 1,
        )),
        suffixIcon: GestureDetector(
          onTap: () {
            setState(() {
              _obscureText = !_obscureText;
            });
          },
          child: Icon(
            _obscureText ? Icons.visibility_off : Icons.visibility,
            color: Const.gold,
          ),
        ),
      ),
    );
  }
}
